package com.example.testdemo.recyclerview_gallery_load;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.testdemo.R;
import com.example.testdemo.recyclerview_gallery_load.loadmore.CommonRcViewHolder;
import com.example.testdemo.recyclerview_gallery_load.loadmore.LoadMoreAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhangwenxiang on 2018/8/9.
 */

public class CardAdapter extends LoadMoreAdapter{
    private List<Integer> mList = new ArrayList<>();
    public CardAdapter(List<Integer> mList) {
        this.mList = mList;
    }


    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public CommonRcViewHolder getViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_card_item, parent, false);
        return new CommonRcViewHolder(itemView);
    }

    @Override
    public void loadData(CommonRcViewHolder holder, int position) {
        ((ImageView)holder.getView(R.id.imageView)).setImageResource(mList.get(position));
    }

    @Override
    public void loadMore() {
        int startPosition = getCount();
        //加载更多
        if(mList.size() < 50){
            mList.add(R.mipmap.a4);
            mList.add(R.mipmap.a5);
//            int endPosition = getCount()-1;
            notifyDataSetChanged();
        }else{
            //设置加载更多字体
            setLoadMoreText("没有更多了");
        }
    }
}
